package com.itggm.handlers;

import com.itggm.Result.ResponseResult;
import com.itggm.Result.ResponseStatus;
import com.itggm.exception.BusinessException;
import org.apache.shiro.authz.UnauthorizedException;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;

/**
 * @author: ggm
 * @data 2024年12月20日 20:24
 */
@RestControllerAdvice
public class GlobalExceptionHandler {
    @ExceptionHandler(Exception.class)
    public ResponseResult allExceptionHandler(Exception e){
        e.printStackTrace();
        return ResponseResult.error();
    }
    @ExceptionHandler(BusinessException.class)
    public ResponseResult   BusinessExceptionHandler(BusinessException e){
        return  ResponseResult.error().message(e.getInfo());
    }

    @ExceptionHandler(UnauthorizedException.class)
    public ResponseResult   unauthorizedExceptionHandler(UnauthorizedException e){
        return  ResponseResult.error().code(ResponseStatus.UN_PERMISSION).message(ResponseStatus.UN_PERMISSION.getMessage());
    }

}
